<template>
  <view style="padding-bottom: 50px;" v-if="carts.length !==0">
     <!-- 收货地址组件 -->
    <my-address></my-address>
    
    <!-- 购物车标题栏 -->
    <view class="cart-title">
       <!-- 左侧图标 -->
       <uni-icons type="shop" size="25"></uni-icons>
       <!-- 描述文本 -->
       <text class="cart-title-text">购物车</text>
    </view>
    
    <!-- 购物车商品栏 -->
   <!-- <block v-for="(cart,c) in carts" :key="c">
       <view class="cart-list-box"> -->
         <!-- 左侧 -->
       <!--   <view class="cart-list-left"> -->
             <!-- 图标 -->
       <!--       <label class="radio-box">
                <radio value="" color="red" />
              </label> -->
              <!-- 图片 -->
              <!-- <image :src="cart.goods_small_logo" mode=""></image> -->
          <!-- </view> -->
          <!-- 右侧 -->
           <!-- <view class="cart-list-right"> -->
              <!-- 商品信息 -->
               <!-- <text class="cart-right-text">{{cart.goods_name}}</text> -->
               <!-- 商品价格数量 -->
            <!--   <view class="cart-right-price">
                   <text class="right-price-text">￥{{cart.goods_price}}.00</text>
                   <view class="right-price-num">
                     <span>+</span>
                     <span>1</span>
                     <span>-</span>
                   </view>
               </view>
           </view>
       </view>
    </block> -->
    
   
   
   
  <!-- 循环渲染购物车信息 -->
   <uni-swipe-action>
     <block v-for="(c,i) in carts" :key="i">
       <uni-swipe-action-item  :right-options="options" @click="goodsDelete(c)">
       		<my-goods :good=c :showRadio="true" @radio-change="radioChangeHandler" :showNum="true" @num-change="numChangeHandler"></my-goods>
       	</uni-swipe-action-item>
    </block>
   </uni-swipe-action>
   
   <!-- 底部自定义结算组件 -->
    <my-settle></my-settle>
  </view>
  
  <view class="empty-cart" v-else>
    <image src="../../static/cart_empty@2x.png" class="empty-img" mode=""></image>
    <text class="tip-text">空空如也~</text>
  </view>
</template>

<script>
 import badgeMix from '@/mixins/tabBar-badge.js'
 import {mapState} from 'vuex'
  export default {
    mixins:[badgeMix],  
    computed:{
      ...mapState({
        carts:state=>state.cart.carts
      })
    },
    data() {
      return {
         options:[
                {
                    text: '删除',
                    style: {
                        backgroundColor: '#c00000'
                    }
                }, 
              ]
      };
    },
    methods:{
      radioChangeHandler(e){
          this.$store.commit('updateGoodsState',e)
      },
      numChangeHandler(e){
        this.$store.commit('updateGoodsState',e)
      },
      goodsDelete(e){
        this.$store.commit('goodsDelete',e)
      }
    }
  }
</script>

<style lang="scss">
.cart-title{
  display: flex;
  align-items: center;
  height: 40px;
  padding-left :10px;
  border-bottom: 1px solid #fff;
  .cart-title-text{
    font-size: 16px;
    margin-left: 5px;
  }
}

.empty-cart{
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 150px;
  .empty-img{
    width: 90px;
    height: 90px;
  }
  .tip-text{
    font-size: 12px;
    color: gray;
    margin-top: 15px;
  }
}
</style>
